
<?php 
/* 
Template Name: xoa may 
*/
?>
<?php

  ?>
<?php 
 
if ( !is_user_logged_in() ) 
    {
      ?>

        
              <?php wp_die( __( 'Vui lòng đăng nhập hoặc quay lai trang chủ ! ' ) ); ?>
      
         
     <?php 
          
    }//if ( ! current_user_can( 'list_users' ) ) 
    elseif (is_user_logged_in() )  
 { 
get_header();
    if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      {
       ?>

      
              <?php wp_die( __( 'Vui lòng đăng nhập hoặc quay lai trang chủ ! ' ) ); ?>
      
         
     <?php 

      }//if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
      {
     



    //echo ' nguoiquanli : '.$_POST['nguoiquanli'];
    $ID = $_POST['nguoiquanli'];
    $id_may = $_POST['id_may'];
    //echo ' Id may : '.$id_may;
   // echo 'nguoi dung can xóa: '.$ID;

   
    // xoa nguoi quan lí
?>            
  <?php 
                    if ( isset($_POST['nguoiquanli']) and  $_POST['nguoiquanli'] <>'') 
                      {
                        $ID = $_POST['nguoiquanli'];
                        $xoa_may_userID= $wpdb->delete( 'wp_user_wp_may', array( 'ID' => $ID ), array( '%d' ) );

                        

                              echo "<script>alert('".json_encode('Xóa thành công')."');</script>";
                              $url_phuc = get_bloginfo('siteurl');
                              $er = '/manager-product-set';
                              $noib = $url_phuc.$er ;
                              //echo "<script>location.href='".$noib."'</script>";

                        //echo '<script language="javascript" type="text/javascript"> alert("xóa máy thành công"); window.location.replace("'.$noib.'"); </script>';
                       // echo "<script>alert('".json_encode('Xóa người dùng thành công')."');</script>";
                        //echo "<script>location.href='".UrL."'</script>";
 ?>
<!---------------------------------------------->

  <div id="dialog-form-them-quan-tri" title="Chọn thêm người phân quyền">
        <?php 
     $query_user = "SELECT ID,user_nicename,display_name,user_email,user_registered FROM $wpdb->users" ;
    // WHERE post_type='post'";
    ?>         
           <form action="<?php echo get_bloginfo('template_directory').'/page_xu_li_set_admin.php'?>" method="GET" >
                   <table class="wp-list-table widefat fixed users" cellspacing="0">
                        <thead>
                         <tr>
                           <th scope="col" id="cb"  style=""> </th>
                           <th scope="col" id="username"  style=""> <span>Tài khoản</span></th>
                           <th scope="col" id="name"  style=""><span>Tên người dùng</span></th>
                           <th scope="col" id="email"style=""></th>
                         </tr>
                        </thead>
                        

                         <tbody id="the-list" data-wp-lists="list:user">
            <?php $rows = $wpdb->get_results($query_user);
                 foreach($rows as $post)
                 {
             ?>
                  <tr id="user-<?php $post->ID; ?>" class="alternate">
                       <th scope="row" class="check-column">
                       </th>
                         <td class="username column-username">
                           <strong><?php echo $post->user_nicename;?></strong>
                        </td>
                        <td class="name column-name"><?php echo $post->display_name;?> </td>
                        <td class="email column-email">
                           <input type="hidden" name="idproduct" id="idproduct" value='<?php echo $id_prod;?>'/>
                           <input type="checkbox" name="nqli_<?php echo $post->ID;?>" id="nqli_<?php echo $post->ID;?>" value='<?php echo $post->ID;?>'/>
                        </td>
                                                       
                    </tr><!-- id="user-xyz" class="alternate" -->
            <?php } // end foreach($rows as $post) ?>

             </tbody>
                    </table>

           <div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
            <div class="ui-dialog-buttonset">
              <button type="submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
                <span class="ui-button-text">Chọn</span>
              </button>
              <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
                <span class="ui-button-text">Hủy</span>
              </button>
            </div>
          </div>
            </form>

</div><!-- id="dialog-form-them-quan-tri" title="Chọn thêm người phân quyền" -->
<script type="text/javascript">
  $(function() {
    var name = $( "#name" ),
      name_full = $( "#name_full" ),
      email = $( "#email" ),
      password = $( "#password" ),
      allFields = $( [] ).add( name ).add( name_full ).add( email ).add( password ),
      tips = $( ".validateTips" );
 
    function updateTips( t ) {
      tips
        .text( t )
        .addClass( "ui-state-highlight" );
      setTimeout(function() {
        tips.removeClass( "ui-state-highlight", 1500 );
      }, 500 );
    }
 
    

$( "#dialog-form-them-quan-tri" ).dialog({
      autoOpen: false,
      width: 600,
      modal: true,
    });

$( "#them-quan-tri" )
      .button()
      .click(function() {
        $( "#dialog-form-them-quan-tri" ).dialog( "open" );
      });
$( ".ui-button-text" ).click(function() {
        $( "#dialog-form-them-quan-tri" ).dialog( "close" );
      });


  });
</script>

<div style='margin:20px;'></div>

<div id="tabs" style="min-height: 606px;">
  <ul>
    <li><a href="#tabs-1" style='font-size: 13px;color: #2a789e;width: 134px;'>Người quản li</a></li>
    <li><a href="#tabs-2"style='font-size: 13px;color: #2a789e;width: 134px;' >Người dùng</a></li>
  </ul>
  <div id="tabs-1">
    <h2 style="margin: 3px;font-size: 19px;color: #2a789e;text-align: left;font-weight: bold;">Người quản li</h2>
    <button class="button action"  id="them-quan-tri" style='padding: 3px;margin: 3px;'>Chọn người quản lí</button>
    
  <?php 
    $sql = "SELECT * FROM wp_user_wp_may
            INNER JOIN wp_users
                        ON wp_users.ID = wp_user_wp_may.ID
                        WHERE id_may LIKE '".$id_may."';";  
    //echo $sql ;
     $row = $wpdb->get_results($sql);
     //var_dump($row );

  ?>  
    <p>         
           <form action='#' method="get" >
             <table class="wp-list-table widefat fixed users" cellspacing="0">
                  <thead>
                   <tr>
                     <th scope="col" id="cb"  style=""> </th>
                     <th scope="col" id="username"  style=""> <span>Tài khoản</span></th>
                     <th scope="col" id="name"  style=""><span>Tên người dùng</span></th>
                     <th scope="col" id="email"style=""></th>
                   </tr>
                  </thead>
                  

                   <tbody id="the-list" data-wp-lists="list:user">
      <?php 
        foreach($row as $key=>$value)
       {
        //var_dump($value);//break;
       ?>
            <tr id="user-<?php echo $value->ID; ?>" class="alternate">
                 <th scope="row" class="check-column">
                   <label class="screen-reader-text" for="cb-select-1"></label>
                 </th>
                   <td class="username column-username">
                     <strong><?php echo $value->user_login;?></strong>
                  </td>
                  <td class="name column-name"><?php echo $value->display_name;?></td>
                  <td class="email column-email">
                     <div style="display: inline-block;width: 200px;padding-top: 8px;">
                        <form><fieldset></fieldset></form>
                       
                    <div style='float:left;'>
                        <form action='<?php bloginfo('url');?>/xoa-may' method='POST'>
                           <fieldset>
                            <input type="hidden" name="nguoiquanli" id="nguoiquanli" value='<?php echo $value->ID; ?>' />
                            <input type="hidden" name="id_may" id="id_may" value='<?php echo $id_may;?>' />
                            <input type="submit" name="xoa_<?php echo $value->ID; ?>" id="xoa_<?php echo $value->ID; ?>" value='Xóa'/>
                          </fieldset>
                        </form>
                    </div><!-- style='float:left;' -->
                    </div><!-- style="display: inline-block;width: 200px;padding-top: 8px;"> -->
                  </td>
                                                 
              </tr><!-- id="user-xyz" class="alternate" -->
<?php             
      }// foreach($row as $key=>$value)
  ?>

       </tbody>
              </table>
      </form>

    </p>

  </div><!-- d="tabs-1" -->

  <div id="tabs-2">
    <h2 style="margin: 3px;font-size: 19px;color: #2a789e;text-align: left;font-weight: bold;">Người dùng</h2>
    <button class="button action"  id="them-nguoi-dung" style='padding: 3px;margin: 3px;'>Chọn người dùng</button>
    <p>
      <?php 
     $query_user = "SELECT ID,user_nicename,display_name,user_email,user_registered FROM $wpdb->users" ;
    // WHERE post_type='post'";
    ?>            
         <form action='#' method="get" >
           <table class="wp-list-table widefat fixed users" cellspacing="0">
                <thead>
                 <tr>
                   <th scope="col" id="cb"  style=""> </th>
                   <th scope="col" id="username"  style=""> <span>Tài khoản</span></th>
                   <th scope="col" id="name"  style=""><span>Tên người dùng</span></th>
                   <th scope="col" id="email"style=""></th>
                 </tr>
                </thead>
                

                 <tbody id="the-list" data-wp-lists="list:user">
    <?php $rows = $wpdb->get_results($query_user);
         foreach($rows as $post)
         {
     ?>
          <tr id="user-<?php $post->ID; ?>" class="alternate">
               <th scope="row" class="check-column">
                 <label class="screen-reader-text" for="cb-select-1"></label>
               </th>
                 <td class="username column-username">
                   <strong><?php echo $post->user_nicename;?></strong>
                </td>
                <td class="name column-name"><?php echo $post->display_name;?> </td>
                <td class="email column-email">
                   <div style="display: inline-block;width: 200px;padding-top: 8px;">
                      <form><fieldset></fieldset></form>
                      <!--
                      <div style='float:left;'>
                         <form action='<?php bloginfo('url');?>/edit-user' method='POST'>
                            <fieldset>
                            <input type="hidden" name="sua_edit" id="sua_edit" value='<?php echo $post->ID; ?>'>
                             <input type="submit" name="sua_<?php echo $post->ID;?>" id="sua_<?php echo $post->ID;?>" value='thêm'/>
                            </fieldset>
                        </form>
                     </div><!-- style='float:left;' -->
                  <div style='float:left;'>
                      <form action='<?php bloginfo('url');?>/delete-user' method='POST'>
                         <fieldset>
                          <input type="hidden" name="xoa_user" id="xoa_user" value='<?php echo $post->ID; ?>' />
                          <input type="submit" name="xoa_<?php echo $post->ID;?>" id="xoa_<?php echo $post->ID;?>" value='Xóa'/>
                        </fieldset>
                      </form>
                  </div><!-- style='float:left;' -->
                  </div><!-- style="display: inline-block;width: 200px;padding-top: 8px;"> -->
                </td>
                                               
            </tr><!-- id="user-xyz" class="alternate" -->
    <?php } // end foreach($rows as $post) ?>

     </tbody>
            </table>
    </form>

    </p>
  </div><!-- id="tabs-2" -->
  
</div><!-- id="tabs" -->


<div id="dialog-form-them-nguoi-dung" title="Chọn thêm người phân quyền">
        <?php 
     $query_user = "SELECT ID,user_nicename,display_name,user_email,user_registered FROM $wpdb->users" ;
    // WHERE post_type='post'";
    ?>         
             <form action='#' method="get" >
               <table class="wp-list-table widefat fixed users" cellspacing="0">
                    <thead>
                     <tr>
                       <th scope="col" id="cb"  style=""> </th>
                       <th scope="col" id="username"  style=""> <span>Tài khoản</span></th>
                       <th scope="col" id="name"  style=""><span>Tên người dùng</span></th>
                       <th scope="col" id="email"style=""></th>
                     </tr>
                    </thead>
                    

                     <tbody id="the-list" data-wp-lists="list:user">
        <?php $rows = $wpdb->get_results($query_user);
             foreach($rows as $post)
             {
         ?>
              <tr id="user-<?php $post->ID; ?>" class="alternate">
                   <th scope="row" class="check-column">
                   </th>
                     <td class="username column-username">
                       <strong><?php echo $post->user_nicename;?></strong>
                    </td>
                    <td class="name column-name"><?php echo $post->display_name;?> </td>
                    <td class="email column-email">
                       <div style="display: inline-block;width: 200px;padding-top: 8px;">
                          <form><fieldset></fieldset></form>
                      <div style='float:left;'>
                          <form action='<?php bloginfo('url');?>/delete-user' method='POST'>
                             <fieldset>
                              <input type="hidden" name="xoa_user" id="xoa_user" value='<?php echo $post->ID; ?>' />
                              <input type="checkbox" name="xoa_<?php echo $post->ID;?>" id="xoa_<?php echo $post->ID;?>" value='<?php echo $post->ID;?>'/>
                            </fieldset>
                          </form>
                      </div><!-- style='float:left;' -->
                      </div><!-- style="display: inline-block;width: 200px;padding-top: 8px;"> -->
                    </td>
                                                   
                </tr><!-- id="user-xyz" class="alternate" -->
        <?php } // end foreach($rows as $post) ?>

         </tbody>
                </table>
        </form>

    </div><!-- id="dialog-form-them-nguoi-dung"-->

<!-------------------------------------------------->




                        <?php 
  } else {
  ?>
    echo "<script>alert('".json_encode('Chưa xóa thành công')."');</script>";
    <?php
     $url_phuc = get_bloginfo('siteurl');
     $er = '/quan-li-may';
     $noib = $url_phuc.$er ;
                              // $redirect = $noib; wp_redirect($redirect); exit;
                              // echo '<script language="javascript" type="text/javascript"> alert("xóa máy thành công"); window.location.replace("'.$noib.'"); </script>';
          }
                        
 } //  elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
} //elseif ( ! current_user_can( 'list_users' ) ) ?>
		
<?php get_footer();?>